#ifndef NDD_MY_QSCIDOC_H
#define NDD_MY_QSCIDOC_H
#include <vector>
#include <QWidget>
#include <QByteArray>
#include <qsciscintilla.h>
#include <Scintilla.h>
#include "Conversion.h"

typedef enum {
    SEL_DIR_R2L,
    SEL_DIR_L2R
} SelectDirection;

typedef enum {
    SEL_SORT_BY_NONE,
    SEL_SORT_BY_POSITION,
    SEL_SORT_BY_SELECT_ORDER
} SelectSortType;

struct SelectInfo {
    intptr_t leftPos = 0;
    intptr_t rightPos = 0;
    intptr_t order = -1; // 0 based index
    SelectDirection direction = SEL_DIR_L2R; // L2R or R2L
    intptr_t nbVirtualCaretSpc = 0;
    intptr_t nbVirtualAnchorSpc = 0;

    SelectInfo(intptr_t lPos, intptr_t rPos, intptr_t order, SelectDirection dir = SEL_DIR_L2R, intptr_t vAnchorNbSpc = 0, intptr_t vCaretNbSpc = 0);
    bool Valid() const;
};

typedef std::vector<SelectInfo> SelectInfos;
typedef sptr_t(*SCINTILLA_FUNC) (sptr_t ptr, unsigned int, uptr_t, sptr_t);
typedef sptr_t SCINTILLA_PTR;

class MyQsciDoc : public QWidget
{
	Q_OBJECT

#define REF_EDIT(edit) auto &edit = *(this->getCurrentEditFunc())
public:
	MyQsciDoc(QWidget* parent, std::function<QsciScintilla* ()> func);
	virtual ~MyQsciDoc();

    SelectInfos GetMultipleSelections(SelectSortType sortType = SEL_SORT_BY_NONE);
    void SelectMultipleRanges(const SelectInfos& selections);

    void SetText(const QByteArray& text);
    QByteArray GetText();

    NewLineType GetNewLineType();

    QsciScintilla* operator->();
    bool Valid();

protected:

private:
	QWidget* parentWidget;
	std::function<QsciScintilla* ()> getCurrentEditFunc;
};
#endif // NDD_MY_QSCIDOC_H
